import http.client

'''
发送GET请求:
a.txt. 与服务器建立请求
2. 构建头部
3. 发送GET请求
4. 获取响应并打印
'''
# conn = http.client.HTTPConnection('localhost')
# conn.request('GET', '/agileone/')
# # setCookie = conn.getresponse().getheader('Set-Cookie')
# print(conn.getresponse().reason)

'''
发送POST请求:
a.txt. 与服务器建立连接
2. 构建头部, 正文
3. 发送POST请求
4. 获取响应并打印
'''
conn = http.client.HTTPConnection('localhost')
header = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
data = 'username=admin&password=admin&savelogin=true'
conn.request('POST', '/agileone/index.php/common/login', headers=header, body=data)
response = conn.getresponse().read().decode()
print(response)
